package basic;

import java.io.IOException;

/**
 * @author Cheng Jun
 * Description: 程序的运行环境
 * @version 1.0
 * @date 2021/9/5 10:10
 */
public class RuntimeExample {
    public static void main(String[] args) {
        Runtime runtime = Runtime.getRuntime();
        int cpuNum = runtime.availableProcessors();
        System.out.println("本机的CPU数量为：" + cpuNum);
        runtime.gc();
        System.out.println("本机CPU内核数：" + runtime.availableProcessors());
        System.out.println("最大可用内存空间" + runtime.maxMemory() / 1024 / 1024 + "MB,默认为系统的1/4");
        System.out.println("可用内存空间:" + runtime.totalMemory() / 1024 / 1024 + "MB,默认为系统的1/64");
        System.out.println("空闲内存空间:" + runtime.freeMemory() / 1024 / 1024 + "MB");
        System.out.println("手工GC处理gc()");
        runtime.gc();
        System.out.println("什么是GC？可以由系统自动调用的垃圾释放功能，或者RunTime手工调用的垃圾释放功能");
        try {
            Process exec = runtime.exec("ping www.baidu.com");
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
